package com.burgeon.backend.SHOP.service.Impl;

import com.burgeon.backend.SHOP.entity.Advertising;
import com.burgeon.backend.SHOP.entity.Banner;
import com.burgeon.backend.SHOP.entity.IndexImg;
import com.burgeon.backend.SHOP.entity.Seckill;
import com.burgeon.backend.SHOP.mappers.IndexMapper;
import com.burgeon.backend.SHOP.service.IndexService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class IndexServiceImpl implements IndexService {
    private final static Log logger = LogFactory.getLog(IndexMapper.class);

    @Autowired
    private IndexMapper indexMapper;

    @Override
    public List<Advertising> GetAdvertising(String token) {
        return indexMapper.showAdvertising(token);
    }

    @Override
    public ArrayList<Banner> GetIndexBanner(String token) {
        try {
            return indexMapper.showBanner(token);
        } catch (Exception e) {
            logger.error(e);
            return new ArrayList<>();
        }
    }

    @Override
    public Seckill getSeckill(String token) {
        try {
            Seckill seckill = indexMapper.showSeckill(token);
            seckill.setImg(seckill.getImg()+"?"+((Math.random() * 9 + 1) * 100000));
            return seckill;
        } catch (Exception e) {
            logger.error(e);
            return null;
        }
    }

    @Override
    public IndexImg getIndexImg(String token) {
        try {
            return indexMapper.showIndexImg(token);
        } catch (Exception e) {
            logger.error(e);
            return null;
        }
    }

}
